package trabajoISW2.tests;

import java.util.LinkedList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import trabajoISW2.domain.exceptions.WrongIdException;
import trabajoISW2.domain.exceptions.WrongNameException;
import trabajoISW2.domain.implementations.Book;
import trabajoISW2.domain.implementations.Subject;



public class SubjectTestSuite {

	Subject is;
	List<Book> lb;
	Book b1;
	Book b2;
	SuperTest st;
	
	@Before
	public void  setup(){
		st = new SuperTest();
		st.inicializa();
		lb = new LinkedList<Book>();
		is = st.subject1;
		b1 = st.book1;
		b2 = st.book2;
		
	}
	
	//Pruebas sobre el método setSubjectId
	
	@Test
	public void testSetSubjectId1(){
	
		is.setSubjectId(0);
		is.setSubjectId(Integer.MAX_VALUE);
		is.setSubjectId(Integer.MAX_VALUE - 1);
		is.setSubjectId(1);
	}
	
	@Test(expected = WrongIdException.class)
	public void testSetSubjectId2(){
		is.setSubjectId(-1);
		
	}
	
	@Test(expected = WrongIdException.class)
	public void testSetSubjectId3(){
		is.setSubjectId(Integer.MIN_VALUE);
	}
	
	@Test(expected = WrongIdException.class)
	public void testSetSubjectId4(){
		is.setSubjectId(Integer.MIN_VALUE + 1);
	}
	
	//Pruebas sobre el atributo setName
	
	@Test
	public void testSetName1(){
		is.setName("Hist�rico");
		is.setName("novela rosa");
	}
	
	@Test (expected = WrongNameException.class)
	public void testSetName2(){
		is.setName(null);
		
	}
	
	@Test (expected = WrongNameException.class)
	public void testSetName3(){
		is.setName("");
		
	}
	
	//Pruebas sobre el m�todo setBooks
	
	@Test
	public void testSetBooks1(){
		is.setBooks(lb);
		lb.add(b1);
		is.setBooks(lb);
		lb.add(b2);
		is.setBooks(lb);
	}
	
	@Test (expected = IllegalArgumentException.class)
	public void testSetBooks2(){
		is.setBooks(null);
	}
	
	//Pruebas sobre el método addBook
	
	@Test
	public void testAddBook1(){
		is.addBook(b1);
		is.addBook(b2);
		
	}
	
	@Test (expected = IllegalArgumentException.class)
	public void testAddBook2(){
		is.addBook(null);
	}
	
	//Pruebas sobre removeBook
	
	@Test
	public void testRemoveBook1(){
		is.removeBook(b1);
		is.addBook(b1);
		is.addBook(b1);
		is.removeBook(b2);
		is.removeBook(b1);
	}
	
	@Test (expected = IllegalArgumentException.class)
	public void testRemoveBook2(){
		is.removeBook(null);
	}
	
	


}